<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: red;
            position: absolute;
            left: 0;
            top: 30px;
        }
    </style>
    <script>
        window.onload = function(){
            var button = document.querySelector('button')
            var div = document.querySelector('div')
            button.onclick = () =>{
                var timer = setInterval( function() {
                    var left = div.offsetLeft;
                    div.style.left = left + 7 + 'px'
                    if(left >= 500){
                        clearInterval(timer);
                        div.style.left = '500px'
                    }
                },30)
            }
        }
    </script>
</head>
<body>
    <button>按钮</button>
    <div></div>
</body>
</html>